layui.define(['jquery','layer','form','element'],function(exports){
    var $ = layui.jquery;
    var  layer = layui.layer;
    var form = layui.form();
    var element = layui.element();
    var sysUsers=function(){};

    form.on('checkbox(check)', function(data){
        if(data.elem.checked){
            $("input[name='checkbox']").prop("checked", true);
        }else{
            $("input[name='checkbox']").prop("checked", false);
        }  
        form.render('checkbox');      
    });

    sysUsers.prototype.init=function(){
        var ss=ss;
    }
    //添加用户
    $("#btn_add").click(function(){
        add_dict();
     });
     
     function add_dict() {
        //iframe层
       var index= layer.open({
            type: 2,
            title: '添加用户',
            shadeClose: false,
            shade: 0.8,
            area: ['580px', '610px'],
            content: '?t=user_edit', //iframe的url
            end: function(){ 
                location.reload();
            }
        }); 
        layer.full(index);  
    }
    //修改
    $('button[data-opt=update]').click(function(){
        var t_id=$(this).data('id');
        edit_grade(t_id);
    });
    function edit_grade(id) {
        //iframe层
        var index=layer.open({
            type: 2,
            title: '修改用户',
            shadeClose: false,
            shade: 0.8,
            area: ['580px', '610px'],
            full:true,
            content: '?t=user_edit&id='+id, //iframe的url
            end: function(){ 
                location.reload();
            }
        }); 
        layer.full(index);  
    }
    //删除
    $('button[data-opt=del]').click(function(){
        var id=$(this).data('id');
        layer.confirm('确定删除？',function(index){
            $.post("/srv/sdo.php", {tpl:"del_user_single",id:id}, function (d, e) {  
                if(d=="ok"){
                    layer.msg('删除成功');
                    setTimeout("location.reload()",1000);
                }
            });
        });
    });
    $('button[data-opt=pass]').click(function(){
        var id=$(this).data('id');
        layer.confirm('确定要密码重置？',function(index){
            $.post("/srv/sdo.php", {tpl:"pass_user_single",id:id}, function (d, e) {  
                if(d=="ok"){
                    layer.msg('重置成功');
                    setTimeout("location.reload()",1000);
                }
            });
        });
    });
    //审核
    $("#btn_lock").click(function(){
        var m_val="";
        $("[name='checkbox']:checked").each(function(i, obj) {
			m_val+="'"+$(this).val()+"',";
		});
        if(m_val.lastIndexOf(",")>0){
            m_val=m_val.substring(0,m_val.length-1) ;
        }
        if(m_val.length>0){ 
            $.post("/srv/sdo.php", {tpl:"check_user_more",id:m_val}, function (d, e) {  
                if(d=="ok"){
                    layer.msg('审核通过');
                    setTimeout("location.reload()",1000);
                }
            });
        }else{
            layer.msg('没有选择数据');
        } 
    });
    //刷新
    $("#btn_ref").click(function(){
        location.reload();
    });
    //批量删除
    $("#btn_del").click(function(){
        var m_val="";
        $("[name='checkbox']:checked").each(function(i, obj) {
			m_val+="'"+$(this).val()+"',";
		});
        if(m_val.lastIndexOf(",")>0){
            m_val=m_val.substring(0,m_val.length-1) ;
        }
        if(m_val.length>0){ 
            layer.confirm('确定删除？',function(index){
                $.post("/srv/sdo.php", {tpl:"del_user_more",id:m_val}, function (d, e) {  
                    if(d=="ok"){
                        layer.msg('删除成功');
                        setTimeout("location.reload()",1000);
                    }
                });
            });
        }else{
            layer.msg('没有选择数据');
        } 
    });
    $("#btn_search").bind("click",function(){   
        var nm=$("#s_name").val();
        location.href="?t=user_sys&s_name="+nm;
    }); 

    var sys_user=new sysUsers();
    sys_user.init();
    exports('user_sys',{});
});